﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class FangJia_DAL
    {
        public FangJia_DAL(Context context)
        {
            Context = context;
        }

        public Context Context { get; }

        /// <summary>
        /// 房价列表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="SX"></param>
        /// <param name="Count"></param>
        /// <param name="Count2"></param>
        /// <returns></returns>
        public List<FangJia_Model> FJShow(int index,int size,int SX,out int Count,out int Count2)
        {
            var m=Context.FangJia_Model.AsQueryable().ToList();
            Count = m.Count;
            Count2 = (int)Math.Ceiling(Count * 1.0 / size);

            if(SX==1)
            {
                return m.OrderBy(x => x.FJprice).Skip((index - 1) * size).Take(size).ToList();
            }
            else
            {
                return m.OrderByDescending(x => x.FJprice).Skip((index - 1) * size).Take(size).ToList();
            }
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="MDid"></param>
        /// <param name="MDZT"></param>
        /// <returns></returns>
        public int FJXZT(int FJId, int FJZT)
        {
            var m = Context.FangJia_Model.FirstOrDefault(x => x.FJId == FJId);
            if (FJZT == 0)
            {
                m.FJZT = 0;
            }
            else
            {
                m.FJZT = 1;
            }
            return Context.SaveChanges();
        }
    }
}
